package cn.wolfcode.luowowo.hotel.service.impl;

import cn.wolfcode.luowowo.hotel.domain.HotelTheme;
import cn.wolfcode.luowowo.hotel.mapper.HotelThemeMapper;
import cn.wolfcode.luowowo.hotel.query.HotelThemeQueryObject;
import cn.wolfcode.luowowo.hotel.service.IHotelThemeService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 酒店主题
 *
 * @author win
 */
@Service
public class HotelThemeServiceImpl implements IHotelThemeService {

    @Autowired
    private HotelThemeMapper hotelThemeMapper;

    @Override
    public void deleteById(Long id) {
        hotelThemeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(HotelTheme theme) {
        if (theme == null) {
            return;
        }
        if (theme.getId() == null) {
            hotelThemeMapper.insert(theme);
        } else {
            hotelThemeMapper.updateByPrimaryKey(theme);
        }
        // TODO 后续维护关系
    }

    @Override
    public HotelTheme findById(Long id) {
        return hotelThemeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HotelTheme> selectAll() {
        return hotelThemeMapper.selectAll();
    }

    @Override
    public PageInfo<HotelTheme> query(HotelThemeQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(hotelThemeMapper.selectForList(qo));
    }
}
